package com.lc202310;

import org.apache.commons.collections4.list.TreeList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * Description:
 *
 * @Create 2023/10/9 22:15
 * @Version 1.0
 */
public class Solution2578 {
    public int splitNum(int num) {
        List<Integer> arr = new ArrayList<>();
        while (num > 0) {
            if (num % 10 != 0) {
                arr.add(num % 10);
            }
            num = num / 10;
        }
        arr.sort(Comparator.comparingInt(o -> o));
        int res1 = 0;
        int res2 = 0;
        for (int i = 0; i < arr.size(); i++) {
            if (i % 2 == 0) {
                res1 = res1 * 10 + arr.get(i);
            } else {
                res2 = res2 * 10 + arr.get(i);
            }
        }
        return res1 + res2;
    }

    public int splitNum1(int num) {
        char[] chars = String.valueOf(num).toCharArray();
        Arrays.sort(chars);
        int num1 = 0;
        int num2 = 0;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '0') {
                continue;
            }
            if (i % 2 == 0) {
                num1 = num1 * 10 + (chars[i] - '0');
            } else {
                num2 = num2 * 10 + (chars[i] - '0');
            }
        }
        return num1 + num2;
    }

}
